package demo1.servlet.userManager;

import com.alibaba.fastjson.JSON;
import demo1.pojo.sign;
import demo1.pojo.users;
import demo1.service.userService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/showSignNum")
public class showSignNum extends HttpServlet {//展示签到人数
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset = utf-8");

        List<sign> signList = new ArrayList<>();
        userService userService = new userService();
        try {
            signList = userService.showSignNum();

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        String jsonString = JSON.toJSONString(signList);
        resp.setContentType("text/json;charset=utf-8");
        resp.getWriter().write(jsonString);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
